﻿using System;
using System.Collections.Generic;
using UnityEngine;

// Token: 0x02000072 RID: 114
public class GuidesManager : MonoBehaviour
{
	// Token: 0x1700003E RID: 62
	// (get) Token: 0x06000393 RID: 915 RVA: 0x00016B6C File Offset: 0x00014D6C
	// (set) Token: 0x06000392 RID: 914 RVA: 0x00016B60 File Offset: 0x00014D60
	public GuideDriveManager activeGuide { get; set; }

	// Token: 0x06000394 RID: 916 RVA: 0x00016B74 File Offset: 0x00014D74
	private void Start()
	{
		GuideDriveManager[] componentsInChildren = base.gameObject.GetComponentsInChildren<GuideDriveManager>();
		foreach (GuideDriveManager guideDriveManager in componentsInChildren)
		{
			guideDriveManager.SetManager(this);
			this.guides.Add(guideDriveManager);
		}
	}

	// Token: 0x06000395 RID: 917 RVA: 0x00016BBC File Offset: 0x00014DBC
	private void Update()
	{
		float num = float.MaxValue;
		GuideDriveManager guideDriveManager = null;
		GuideDrive guideDrive = null;
		Vector3 clickPos = Vector3.zero;
		foreach (GuideDriveManager guideDriveManager2 in this.guides)
		{
			GuideDriveManager.CursorCheckData cursorCheckData = guideDriveManager2.CursorCheck();
			if (cursorCheckData.distance < num)
			{
				num = cursorCheckData.distance;
				guideDriveManager = guideDriveManager2;
				guideDrive = cursorCheckData.drive;
				clickPos = cursorCheckData.pos;
			}
		}
		foreach (GuideDriveManager guideDriveManager3 in this.guides)
		{
			if (guideDriveManager3 == guideDriveManager)
			{
				guideDriveManager3.SetOnCursor(guideDrive);
			}
			else
			{
				guideDriveManager3.SetOutCursor();
			}
		}
		if (Input.GetMouseButtonDown(0) && guideDriveManager != null)
		{
			if (guideDriveManager.IsActive && guideDriveManager.MovingDrive == null)
			{
				guideDrive.OnMoveStart(clickPos);
			}
			else
			{
				guideDriveManager.IsActive = true;
			}
		}
		this.illusionCamera.enabled = (this.activeGuide == null);
	}

	// Token: 0x06000396 RID: 918 RVA: 0x00016D18 File Offset: 0x00014F18
	public void Add(GuideDriveManager guide, bool setParent)
	{
		guide.SetManager(this);
		if (setParent)
		{
			guide.transform.SetParent(base.transform, true);
		}
		this.guides.Add(guide);
	}

	// Token: 0x06000397 RID: 919 RVA: 0x00016D48 File Offset: 0x00014F48
	public GuideDriveManager Add(Transform target, bool guideMoveInitiative = true)
	{
		GuideDriveManager guideDriveManager = UnityEngine.Object.Instantiate<GuideDriveManager>(this.original);
		guideDriveManager.gameObject.SetActive(true);
		guideDriveManager.MoveInitiative = guideMoveInitiative;
		guideDriveManager.SetTarget(target);
		this.Add(guideDriveManager, true);
		return guideDriveManager;
	}

	// Token: 0x06000398 RID: 920 RVA: 0x00016D84 File Offset: 0x00014F84
	public void Del(GuideDriveManager guide)
	{
		this.Remove(guide);
		UnityEngine.Object.Destroy(guide.gameObject);
	}

	// Token: 0x06000399 RID: 921 RVA: 0x00016D98 File Offset: 0x00014F98
	public void Del(Transform target)
	{
		foreach (GuideDriveManager guideDriveManager in this.guides)
		{
			if (guideDriveManager.Target == target)
			{
				this.Remove(guideDriveManager);
				UnityEngine.Object.Destroy(guideDriveManager.gameObject);
				break;
			}
		}
	}

	// Token: 0x0600039A RID: 922 RVA: 0x00016E18 File Offset: 0x00015018
	public void Remove(GuideDriveManager guide)
	{
		if (guide.IsActive && this.onChangeActive != null)
		{
			this.onChangeActive(null);
		}
		this.guides.Remove(guide);
	}

	// Token: 0x0600039B RID: 923 RVA: 0x00016E4C File Offset: 0x0001504C
	public void Activate(GuideDriveManager guide)
	{
		foreach (GuideDriveManager guideDriveManager in this.guides)
		{
			if (guideDriveManager != guide)
			{
				guideDriveManager.IsActive = false;
			}
		}
		guide.IsActive = true;
		if (this.onChangeActive != null)
		{
			this.onChangeActive(guide);
		}
	}

	// Token: 0x0600039C RID: 924 RVA: 0x00016ED4 File Offset: 0x000150D4
	public void Activate(Transform target)
	{
		GuideDriveManager guideDriveManager = null;
		foreach (GuideDriveManager guideDriveManager2 in this.guides)
		{
			if (guideDriveManager2.Target == target)
			{
				guideDriveManager = guideDriveManager2;
			}
			else
			{
				guideDriveManager2.IsActive = false;
			}
		}
		guideDriveManager.IsActive = true;
		if (this.onChangeActive != null)
		{
			this.onChangeActive(guideDriveManager);
		}
	}

	// Token: 0x0600039D RID: 925 RVA: 0x00016F68 File Offset: 0x00015168
	public void Set_OnChangeActions(Action<GuideDriveManager> onChangeActive, Action<Transform> onChangeMove)
	{
		this.onChangeActive = onChangeActive;
		this.onChangeMove = onChangeMove;
	}

	// Token: 0x0600039E RID: 926 RVA: 0x00016F78 File Offset: 0x00015178
	public void OnChangeTransform(Transform transform)
	{
		if (this.onChangeMove != null)
		{
			this.onChangeMove(transform);
		}
	}

	// Token: 0x04000328 RID: 808
	[SerializeField]
	private GuideDriveManager original;

	// Token: 0x04000329 RID: 809
	private List<GuideDriveManager> guides = new List<GuideDriveManager>();

	// Token: 0x0400032A RID: 810
	[SerializeField]
	private IllusionCamera illusionCamera;

	// Token: 0x0400032C RID: 812
	private Action<GuideDriveManager> onChangeActive;

	// Token: 0x0400032D RID: 813
	private Action<Transform> onChangeMove;
}
